package com.dhcc.android.base.utils;

import android.view.View;

import java.math.BigDecimal;

import srs.GPS.GPSControl;
import srs.Geometry.IGeometry;
import srs.Geometry.IPolygon;
import srs.Geometry.IPolyline;

public class BtnUtil {


	/**获取当前纬度
	 * @param v
	 * @return
	 */
	public static String getLatitudeCurrent(View v){
		GPSControl gps = GPSControl.getInstance();
		gps.StartGPSControl(v, 2);
		double lat = gps.GPSLatitude;
		String valueLatitude=new BigDecimal(lat).divide(new BigDecimal(1.0),6,BigDecimal.ROUND_HALF_DOWN).toString();
		return valueLatitude;
	}
	
	/*获取当前经度*
	 * @param v
	 * @return
	 */
	public static String getLongitudeCurrent(View v){
		GPSControl gps = GPSControl.getInstance();
		gps.StartGPSControl(v, 2);
		double lon = gps.GPSLongitude;
		String valueLongitude=new BigDecimal(lon).divide(new BigDecimal(1.0),6,BigDecimal.ROUND_HALF_DOWN).toString();
		return valueLongitude;
	}
	
	/**计算面积（平方米）
	 * @param rGeo
	 * @return
	 */
	public static String getArea(IGeometry rGeo){
		if(rGeo!=null&&rGeo instanceof IPolygon){
			String valueArea=new BigDecimal(((IPolygon)rGeo).Area()).divide(new BigDecimal(1.0),2,BigDecimal.ROUND_HALF_DOWN).toString();
			return valueArea;
		}
		return null;
	}
	
	/**计算周长
	 * @param rGeo
	 * @return
	 */
	public static String getLength(IGeometry rGeo){
		if(rGeo!=null&&rGeo instanceof IPolygon){
			String valueLength=new BigDecimal(((IPolygon)rGeo).Length()).divide(new BigDecimal(1.0),2,BigDecimal.ROUND_HALF_DOWN).toString();
			return valueLength;
		}else if(rGeo!=null&&rGeo instanceof IPolyline){
			String valueLength=new BigDecimal(((IPolyline)rGeo).Length()).divide(new BigDecimal(1.0),2,BigDecimal.ROUND_HALF_DOWN).toString();
			return valueLength;
		}
		return null;
	}
	

}
